package Demo1;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Operator {
    static Student stu[];
    static Teacher teacher[];
    static Course course[];
    static Score score[];
    static int stuNum,teacherNum,courseNum;
    static{
        stu=new Student[20];
        teacher=new Teacher[2];
        course=new Course[3];
        score=new Score[10];
        //学生数据
        String stuNo[]={"20240001","20240002","20240003","20240004","20240005","20240006","20240007","20240008","20240009","20240010"};
        String stuName[]={"张三","李四","王芳","刘洋","陈晓","杨静","赵磊","孙悦","周强","吴敏"};
        String password[]={"20240001","20240002","20240003","20240004","20240005","20240006","20240007","20240008","20240009","20240010"};
        char gender[]={'男','男','女','男','女','女','男','女','男','女'};
        //课程数据
        String courseNo[]={"CS101","MA102","EN201"};
        String courseName[]={"计算机科学基础","高等数学","英语写作"};
        String courseType[]={"必修","必修","选修"};
        int courseNum[]={60, 75, 45};
        int selectCourseMaxNum[]={10,20,60};
        float credit[]={3.0f, 4, 2};
        //教师信息
        String teacherNo[]={"011","012"};
        String teacherName[]={"root","admin"};
        String teacherGen[]={"女","男"};
        String teacherPWD[]={"011","012"};
        String teacherType[]={"teacher","admin"};
        //成绩信息
        double scoreS[]={66,88,89,90,91,92,93,98,99,88};
        for (int i = 0; i < 10; i++) {
            stu[i] = new Student(stuNo[i], stuName[i], password[i], gender[i]);
        }

        for (int i = 0; i < 3; i++) {
            course[i] = new Course(courseNo[i], courseName[i], courseType[i], selectCourseMaxNum[i], courseNum[i],
                    credit[i]);
        }
        for (int i = 0; i < 2; i++) {
            teacher[i] = new Teacher(teacherNo[i], teacherName[i], teacherGen[i], teacherPWD[i], teacherType[i]);
        }
        for (int i = 0; i < 10; i++) {
            score[i]=new Score(stuNo[i],stuName[i],courseNo[1],courseName[1],scoreS[i]);
        }
    }
    public void operate() throws IOException{
        System.out.println("请输入用户名(教师编号或学号)和密码：");
        InputStreamReader isr=new InputStreamReader(System.in);
        BufferedReader br=new BufferedReader(isr);
        String userId=br.readLine();
        String pwd=br.readLine();
        String result=new Operator().checkUser(userId, pwd);
        if("admin".equals(result)){
            adminReadMe();
            int inData=Integer.parseInt(br.readLine());
            adminOperate(inData);
        }else if("teacher".equals(result)){
            teacherReadMe();
            int inData=Integer.parseInt(br.readLine());//完善用户的输入，从两个方面着手：一是用户输入其他类型的数据，系统不会异常终止，二是用户可以连续操作。
            teacherOperate(inData);
        }else if("student".equals(result)){
            studentReadMe();
            int inData=Integer.parseInt(br.readLine());
            studentOperate(inData);
        }else{
            System.exit(0);
        }

    }
    /*
     * 检查用户身份
     */
    public String checkUser(String uid,String pwd){
        for (int i = 0; i < teacher.length; i++) {
            System.out.println("*******");
            if(uid.equals(teacher[i].getTeacherNo())&&pwd.equals(teacher[i].getPassword())){
                if("admin".equals(teacher[i].getUserType())){
                    return "admin";
                }
                return "teacher";
            }
        }
        for (int i = 0; i <stu.length; i++) {
            if(uid.equals(stu[i].getStuNo())&&pwd.equals(stu[i].getPassword())){
                return "student";
            }
        }
        return "incorrect";
    }
    /**
     * 教师管理员使用说明
     */
    public void adminReadMe(){
        System.out.println("老师欢迎您！");
        System.out.println("请选择您要进行的操作：");
        System.out.println("说明：1.显示学生信息请输入11;");
        System.out.println("     2.添加学生信息请输入12;");
        System.out.println("     3.修改学生信息请输入13;");
        System.out.println("     4.删除学生信息请输入14;");
        System.out.println("=========================");
        System.out.println("     5.显示教师信息请输入21;");
        System.out.println("     6.添加教师信息请输入22;");
        System.out.println("     7.修改教师信息请输入23;");
        System.out.println("     8.删除教师信息请输入24;");
        System.out.println("=========================");
        System.out.println("     9.显示课程信息请输入31;");
        System.out.println("     10.添加课程信息请输入32;");
        System.out.println("     11.修改课程信息请输入33;");
        System.out.println("     12.删除课程信息请输入34;");
        System.out.println("=========================");
        System.out.println("     13.显示学生选课程信息请输入41;");
        System.out.println("=========================");
        System.out.println("     14.显示学生课程成绩请输入51;");
        System.out.println("=========================");
        System.out.println("     15.退出，请输入其他两位数。;");
    }
    /**
     * 教师使用说明
     */
    public void teacherReadMe(){
        System.out.println("老师欢迎您！");
        System.out.println("请选择您要进行的操作：");
        System.out.println("说明：1.显示学生信息请输入11;");
        System.out.println("=========================");
        System.out.println("     2.显示教师信息请输入21;");
        System.out.println("=========================");
        System.out.println("     3.显示课程信息请输入31;");
        System.out.println("=========================");
        System.out.println("     4.显示学生选课程信息请输入41;");
        System.out.println("=========================");
        System.out.println("     5.显示学生课程成绩请输入51;");
        System.out.println("     6.录入学生课程成绩请输入52;");
        System.out.println("=========================");
        System.out.println("     7.查询学生信息请输入61;");
        System.out.println("     7.退出，请输入其他两位数。;");
    }
    /**
     * 学生使用说明
     */
    public void studentReadMe(){
        System.out.println("同学欢迎您！");
        System.out.println("请选择您要进行的操作：");
        System.out.println("说明：1.显示学生信息请输入11;");
        System.out.println("=========================");
        System.out.println("     2.显示课程信息请输入21;");
        System.out.println("=========================");
        System.out.println("     3.显示学生选课程信息请输入31;");
        System.out.println("     4.学生选课32;");
        System.out.println("=========================");
        System.out.println("     5.显示学生课程成绩请输入51;");
    }
    public void teacherOperate(int inData){
        if("11".equals(inData+"")){
            if(stu!=null){
                for (int i = 0; i < stu.length; i++) {
                    System.out.println(stu[i]);
                }
            }else{
                System.out.println("没有学生信息可显示，请选择其他操作。");
            }
        }else if("21".equals(inData+"")){
            if(teacher!=null) {
                for (int i = 0; i < teacher.length; i++) {
                    System.out.println(teacher[i]);
                }
            }else{
                    System.out.println("没有教师信息可显示，请选择其他操作。");
                }
            }else if("31".equals(inData+"")) {
            if (course != null) {
                for (int i = 0; i < course.length; i++) {
                    System.out.println(course[i]);
                }
            } else {
                System.out.println("没有课程信息可显示，请选择其他操作。");
            }
        }else if("41".equals(inData+"")){
            System.out.println("显示学生选课信息：");
//           showSelect();
        }else if("51".equals(inData+"")){
            if(score!=null){
                for (int i = 0; i < score.length; i++) {
                    System.out.println(score[i]);
                }
            }else{
                System.out.println("没有成绩信息可显示，请选择其他操作。");
            }
        }else if("52".equals(inData+"")) {
            System.out.println("录入学生课程成绩：");
//           addGrade();
        }else if("61".equals(inData+"")){
            Scanner scanner=new Scanner(System.in);
            String n=scanner.nextLine();
            boolean flag=false;
            for (int i = 0; i < 10; i++) {
                if(n.equals(stu[i].getStuNo())){
                    System.out.println(stu[i].getStuNo()+","+stu[i].getStuName()+","+stu[i].getPassword()+","+stu[i].getGender());
                    flag=true;
                }
                if(flag==false){
                    System.out.println("未找到相关学生。");
                }
            }

        }else{
            System.out.println("您输入的数据错误！退出系统。");
        }
    }
    public void studentOperate(int inData){//完善
        if("11".equals(inData+"")){
            if(stu!=null){
                for (int i = 0; i < stu.length; i++) {
                    System.out.println(stu[i]);
                }
            }else{
                System.out.println("没有学生信息可显示，请选择其他操作。");
            }
        }else if("21".equals(inData+"")) {
            if (course != null) {
                for (int i = 0; i < course.length; i++) {
                    System.out.println(course[i]);
                }
            } else {
                System.out.println("没有课程信息可显示，请选择其他操作。");
            }
        }else if("31".equals(inData+"")){
            System.out.println("显示学生选课信息：");
//           showSelect();
        }else if("51".equals(inData+"")){
            if(score!=null) {
                for (int i = 0; i < score.length; i++) {
                    System.out.println(score[i]);
                }
                }else{
                System.out.println("没有成绩信息可显示，请选择其他操作。");
                }
        }else{
            System.out.println("您输入的数据错误！退出系统。");
        }
    }

    public void adminOperate(int inData) {
        if ("11".equals(inData + "")) {
            if (stu != null) {
                for (int i = 0; i < stu.length; i++) {
                    System.out.println(stu[i]);
                }
            } else {
                System.out.println("没有学生信息可显示，请选择其他操作。");
            }
        }else if("12".equals(inData+"")) {
            stu[10]=new Student("6020240011","狗蛋","6020240011",'男');
            for (int i = 0; i < stu.length; i++) {
                System.out.println(stu[i]);
            }
        }else if("13".equals(inData+"")){
            System.out.println("修改学生信息：");
//            modifyStudent();
        }else if("14".equals(inData+"")){
            System.out.println("删除学生信息：");
//            deleteStudent();
        }else if("21".equals(inData+"")) {
            if (teacher != null) {
                for (int i = 0; i < teacher.length; i++) {
                    System.out.println(teacher[i]);
                }
            } else {
                System.out.println("没有教师信息可显示，请选择其他操作。");
            }
        }else if("22".equals(inData+"")){
            System.out.println("添加教师信息：");
//            addTeacher();
        }else if("23".equals(inData+"")){
            System.out.println("修改教师信息：");
//            modifyTeacher();
        }else if("24".equals(inData+"")){
            System.out.println("删除教师信息：");
//            deleteTeacher();
        }else if("31".equals(inData+"")) {
            if (course != null) {
                for (int i = 0; i < course.length; i++) {
                    System.out.println(course[i]);
                }
            } else {
                System.out.println("没有课程信息可显示，请选择其他操作。");
            }
        }else if("32".equals(inData+"")){
            System.out.println("添加课程信息：");
//            addCourse();
        }else if("33".equals(inData+"")){
            System.out.println("修改课程信息：");
//            modifyCourse();
        }else if("34".equals(inData+"")){
            System.out.println("删除课程信息：");
//            deleteCourse();
        }else if("41".equals(inData+"")){
            System.out.println("显示学生选课信息：");
//            showSelect();
        }else if("51".equals(inData+"")){
            if(score!=null){
                for (int i = 0; i < score.length; i++) {
                    System.out.println(score[i]);
                }
            }else{
                System.out.println("没有成绩信息可显示，请选择其他操作。");
            }
        }else{
            System.out.println("您输入的数据错误！退出系统。");
        }
    }
}
